﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VIES;

namespace VIES.Tests.UnitTests
{
    /// <summary>
    /// Unit test class for the VIES library
    /// </summary>
    /// <remarks>Philipp Schosteritsch, SCHOSTE.COM</remarks>
    [TestClass]
    public class WebServiceClientTest
    {
        /// <summary>
        /// Tests the verify method with an bad VAT.
        /// Expects an ArgumentException
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestVerifyNull()
        {
            var vatInfo = WebService.Instance.Verify(null);
            Assert.Fail("Expected exception was not thrown");
        }

        /// <summary>
        /// Tests the verify method with an bad VAT.
        /// Expects an ArgumentException
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The VAT number is invalid")]
        public void TestVerifyBadNumber()
        {
            var vatInfo = WebService.Instance.Verify("A");
            Assert.Fail("Expected exception was not thrown");
        }

        /// <summary>
        /// Tests the verify method with a valid VAT.
        /// Expects non null VAT information with the
        /// Valid field set to true
        /// </summary>
        [TestMethod]
        public void TestVerifyValidNumber()
        {
            var vatInfo = WebService.Instance.Verify("ATU61220627");
            Assert.IsNotNull(vatInfo);
            Assert.IsTrue(vatInfo.Valid);
        }

        /// <summary>
        /// Tests the verify method with an invalid VAT.
        /// Expects non null VAT information with the
        /// Valid field set to false
        /// </summary>
        [TestMethod]
        public void TestVerifyInValidNumber()
        {
            var vatInfo = WebService.Instance.Verify("ATX12345678");
            Assert.IsNotNull(vatInfo);
            Assert.IsFalse(vatInfo.Valid);
        }
    }
}
